﻿<!DOCTYPE html>
<html lang="cn">

<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>登陆页面</title>

	<link rel="stylesheet" type="text/css" href="../static/style.css">
	<link href="../static/css/root.css" rel="stylesheet">

	<script type="text/javascript" src="../static/jquery.min_1.js"></script>
	<script type="text/javascript" src="../static/vector_1.js"></script>
</head>

<body>
	<div id="container" style="background:#A36; color:#FFF">
		<div id="output">
			<div class="containerT">
				<h1>非常欢迎使用本软件！</h1>
				<form class="form" id="entry_form" method="post">
					<input type="text" placeholder="学号" id="entry_name" name="loginName" autocomplete="off">
					<input type="password" placeholder="密码" id="entry_password" name="loginPassword" spellcheck =“false”>
					<!--<button type="submit" id="entry_btn" style="width: 180px;">登录</button>-->
					<button type="button" id="entry_btn" style="width: 180px;" onclick="login()">登录</button>
					<br>
					<br>
					<div class="footer-links row">
						<div class="col-xs-7"><a href="#" style="color: #696969;" onclick="trunToReg()"><i class="fa fa-sign-in" style="color:#696969;"></i> 注册</a></div>
						<div class="col-xs-3 text-right"><a href="#" style="color: #696969;" onclick="alert('功能尚未开放！')"><i class="fa fa-lock" style="color:#696969;"></i> 忘记密码</a></div>
					</div>
				</form>
			</div>
		</div>
	</div>

	<script>
		async function login() {
			const username = document.querySelector('#entry_name').value     // 获取用户名
			const password = document.querySelector('#entry_password').value // 获取密码
			try {
				// const res = await fetch('/login/Page_Login_index.html', {
			    const res = await fetch('/Page_Login_index.html', {
					method: 'POST',
					body: JSON.stringify({ username, password }),
					headers: {
						'Content-Type': 'application/json'
					}
				})
				const json = await res.json()
				console.log(json)
				const { error, msg, userID } = json
				if (error) return alert(error) // 错误
				if (msg) {

				    localStorage.setItem('token', msg)
				    window.location.href="http://fanggx.xyz/list";
				}
			} catch (err) {
				console.error('未知错误', err)
				alert('未知错误，请稍后重试')
			}
		}
		
		function trunToReg() {
		    window.location.href="http://fanggx.xyz/register"
		}
	</script>
	<script type="text/javascript">
		$(function () {
			Victor("container", "output");   //登录背景函数
			$("#entry_name").focus();
			$(document).keydown(function (event) {
				if (event.keyCode == 13) {
					$("#entry_btn").click();
				}
			});
		});
	</script>

</body>

</html>